/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package de.hsmannheim.pepa.patientenportal.apanwep.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import de.hsmannheim.pepa.patientenportal.apanwep.service.ClpSerializer;
import de.hsmannheim.pepa.patientenportal.apanwep.service.network_access_pointsLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Cedric Nana
 */
public class network_access_pointsClp extends BaseModelImpl<network_access_points>
	implements network_access_points {
	public network_access_pointsClp() {
	}

	@Override
	public Class<?> getModelClass() {
		return network_access_points.class;
	}

	@Override
	public String getModelClassName() {
		return network_access_points.class.getName();
	}

	@Override
	public long getPrimaryKey() {
		return _ID;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setID(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _ID;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("ID", getID());
		attributes.put("Identifier", getIdentifier());
		attributes.put("type", getType());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long ID = (Long)attributes.get("ID");

		if (ID != null) {
			setID(ID);
		}

		String Identifier = (String)attributes.get("Identifier");

		if (Identifier != null) {
			setIdentifier(Identifier);
		}

		Long type = (Long)attributes.get("type");

		if (type != null) {
			setType(type);
		}
	}

	@Override
	public long getID() {
		return _ID;
	}

	@Override
	public void setID(long ID) {
		_ID = ID;

		if (_network_access_pointsRemoteModel != null) {
			try {
				Class<?> clazz = _network_access_pointsRemoteModel.getClass();

				Method method = clazz.getMethod("setID", long.class);

				method.invoke(_network_access_pointsRemoteModel, ID);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public String getIdentifier() {
		return _Identifier;
	}

	@Override
	public void setIdentifier(String Identifier) {
		_Identifier = Identifier;

		if (_network_access_pointsRemoteModel != null) {
			try {
				Class<?> clazz = _network_access_pointsRemoteModel.getClass();

				Method method = clazz.getMethod("setIdentifier", String.class);

				method.invoke(_network_access_pointsRemoteModel, Identifier);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	@Override
	public long getType() {
		return _type;
	}

	@Override
	public void setType(long type) {
		_type = type;

		if (_network_access_pointsRemoteModel != null) {
			try {
				Class<?> clazz = _network_access_pointsRemoteModel.getClass();

				Method method = clazz.getMethod("setType", long.class);

				method.invoke(_network_access_pointsRemoteModel, type);
			}
			catch (Exception e) {
				throw new UnsupportedOperationException(e);
			}
		}
	}

	public BaseModel<?> getnetwork_access_pointsRemoteModel() {
		return _network_access_pointsRemoteModel;
	}

	public void setnetwork_access_pointsRemoteModel(
		BaseModel<?> network_access_pointsRemoteModel) {
		_network_access_pointsRemoteModel = network_access_pointsRemoteModel;
	}

	public Object invokeOnRemoteModel(String methodName,
		Class<?>[] parameterTypes, Object[] parameterValues)
		throws Exception {
		Object[] remoteParameterValues = new Object[parameterValues.length];

		for (int i = 0; i < parameterValues.length; i++) {
			if (parameterValues[i] != null) {
				remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
			}
		}

		Class<?> remoteModelClass = _network_access_pointsRemoteModel.getClass();

		ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

		Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

		for (int i = 0; i < parameterTypes.length; i++) {
			if (parameterTypes[i].isPrimitive()) {
				remoteParameterTypes[i] = parameterTypes[i];
			}
			else {
				String parameterTypeName = parameterTypes[i].getName();

				remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
			}
		}

		Method method = remoteModelClass.getMethod(methodName,
				remoteParameterTypes);

		Object returnValue = method.invoke(_network_access_pointsRemoteModel,
				remoteParameterValues);

		if (returnValue != null) {
			returnValue = ClpSerializer.translateOutput(returnValue);
		}

		return returnValue;
	}

	@Override
	public void persist() throws SystemException {
		if (this.isNew()) {
			network_access_pointsLocalServiceUtil.addnetwork_access_points(this);
		}
		else {
			network_access_pointsLocalServiceUtil.updatenetwork_access_points(this);
		}
	}

	@Override
	public network_access_points toEscapedModel() {
		return (network_access_points)ProxyUtil.newProxyInstance(network_access_points.class.getClassLoader(),
			new Class[] { network_access_points.class },
			new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		network_access_pointsClp clone = new network_access_pointsClp();

		clone.setID(getID());
		clone.setIdentifier(getIdentifier());
		clone.setType(getType());

		return clone;
	}

	@Override
	public int compareTo(network_access_points network_access_points) {
		long primaryKey = network_access_points.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof network_access_pointsClp)) {
			return false;
		}

		network_access_pointsClp network_access_points = (network_access_pointsClp)obj;

		long primaryKey = network_access_points.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(7);

		sb.append("{ID=");
		sb.append(getID());
		sb.append(", Identifier=");
		sb.append(getIdentifier());
		sb.append(", type=");
		sb.append(getType());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(13);

		sb.append("<model><model-name>");
		sb.append(
			"de.hsmannheim.pepa.patientenportal.apanwep.model.network_access_points");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>ID</column-name><column-value><![CDATA[");
		sb.append(getID());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>Identifier</column-name><column-value><![CDATA[");
		sb.append(getIdentifier());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>type</column-name><column-value><![CDATA[");
		sb.append(getType());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _ID;
	private String _Identifier;
	private long _type;
	private BaseModel<?> _network_access_pointsRemoteModel;
}